<?php
/**
 * @since 23.07.2011
 * @author Akulov Denis
 */
class MVC_Controller_Acp extends MVC_Controller_Base {

    public function _accessDeniedHandler($strMethodName, $arParams) {
        $this->_redirect('/athorization');
    }


    protected function _addTitle ($title) {
        $this->_addHookInsert('title', 'HTML_Title')
             ->_addVariable('title', $title);
    }


    public function _pageNotFound() {
        die('Page not found');
    }


    public function _isRefererValid ($strNameOfModel) {
        $strReferer = $this->_SERVER_Item('HTTP_REFERER');

        // Отрезаем GET - запрос
        $strReferer = substr($strReferer, 0, strlen($strReferer) - strlen(strchr($strReferer, '?')));

        // Отрезаем косую черту в конце URL
        $strReferer = (substr($strReferer, -1) == '/')?substr($strReferer, 0, -1):$strReferer;

        if ($this->_getDomain() != substr($strReferer, 0, strlen($this->_getDomain()))) {
            return false;
        }

        if ($strNameOfModel != substr($strReferer, -strlen($strNameOfModel), strlen($strReferer))) {
            return false;
        }

        return true;
    }


    protected function _getDomain () {
            return $this->_getConfig()->getAttribute('PROTOCOL', 'MAIN').
            $this->_getConfig()->getAttribute('BASE_URL', 'MAIN');
    }

}